#!/usr/bin/env python
# -*- coding:utf-8 -*-
class Chat(object):
    totalInventory = 10
    callbacks = []
    carts = {}
    def __init__(self, id=None):
        self.observers = []
        self.messages = []

    def register(self, callback):
        self.callbacks.append(callback)

    def add_message(self, message):
        try:
            self.messages.append(message)
            self.notifyCallbacks()
        finally:
            self.observers = []

    def notifyCallbacks(self):
        callbacks_temp=[]
        for c in self.callbacks:
            l=list(c.keys())
            if(self.messages[0]['roomId']==l[0]):
                c[str(l[0])](self.messages)
                c.pop(l[0])
            else:
                callbacks_temp.append(c)
        self.callbacks = callbacks_temp
        self.messages = []
